/*!
    \file    hid_printer_wrapper.h
    \brief   header file for the hid_printer_wrapper.c file

    \version 2020-08-01, V3.0.0, firmware for GD32F30x
    \version 2022-06-10, V3.1.0, firmware for GD32F30x
*/

/*
    Copyright (c) 2022, GigaDevice Semiconductor Inc.

    Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

    1. Redistributions of source code must retain the above copyright notice, this 
       list of conditions and the following disclaimer.
    2. Redistributions in binary form must reproduce the above copyright notice, 
       this list of conditions and the following disclaimer in the documentation 
       and/or other materials provided with the distribution.
    3. Neither the name of the copyright holder nor the names of its contributors 
       may be used to endorse or promote products derived from this software without 
       specific prior written permission.

    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
OF SUCH DAMAGE.
*/

#ifndef HID_composite_keyboard_mouse_cdc_H
#define HID_composite_keyboard_mouse_cdc_H

#include "usbd_enum.h"
#include "usb_hid.h"
#include "cdc_acm_core.h"


typedef struct
{
    uint32_t protocol;
    uint32_t idle_state;

    uint8_t data[HID_KEYBOARD_IN_PACKET_SIZE];
    volatile uint8_t prev_transfer_complete;
} usb_hid_keyboard_handler;

typedef struct
{
    uint32_t protocol;
    uint32_t idle_state;

    uint8_t data[HID_MOUSE_IN_PACKET_SIZE];
    volatile uint8_t prev_transfer_complete;
} usb_hid_mouse_handler;

typedef struct {
    acm_line line_coding;                               /* 串口参数 */

    uint8_t data_receive[CDC_ACM_DATA_PACKET_SIZE];     /* 待接收的缓存 */

    volatile uint8_t send_ing;                          /* 发送状态 */
} usb_cdc_acm_handler;

typedef struct
{
    void (*mice_itf_config) (void);
    void (*mice_itf_data_process) (usb_dev *udev);
} mice_fop_handler;


#pragma pack(1)

typedef struct
{
    usb_desc_header  header;              /*!< regular descriptor header containing the descriptor's type and length */
    uint8_t bFirstInterface;              /*!< bFirstInterface */
    uint8_t bInterfaceCount;              /*!< bInterfaceCount */
    uint8_t bFunctionClass;               /*!< bFunctionClass */
    uint8_t bFunctionSubClass;            /*!< bFunctionSubClass */
    uint8_t bFunctionProtocol;            /*!< bFunctionProtocol */
    uint8_t iFunction;                    /*!< iFunction  */
} usb_desc_IAD;

#pragma pack()

typedef struct
{
    usb_desc_config                 config;

    usb_desc_IAD                    iad_keyboard;
    usb_desc_itf                    interface_keyboard;
    usb_desc_hid                    vendor_keyboard;
    usb_desc_ep                     epin_keyboard;
    usb_desc_ep                     epout_keyboard;

    usb_desc_IAD                    iad_mouse;
    usb_desc_itf                    interface_mouse;
    usb_desc_hid                    vendor_mouse;
    usb_desc_ep                     epin_mouse;

    usb_desc_IAD                    iad_cdc;
    usb_desc_itf                    interface_cdc_cmd;
    usb_desc_header_func            cdc_header;
    usb_desc_call_managment_func    cdc_call_managment;
    usb_desc_acm_func               cdc_acm;
    usb_desc_union_func             cdc_union;
    usb_desc_ep                     epin_cdc_cmd;

    usb_desc_itf                    interface_cdc_data;
    usb_desc_ep                     epout_cdc_data;
    usb_desc_ep                     epin_cdc_data;
} usb_hid_keyboard_mouse_cdc_desc_config_set_struct;



void hid_keyboard_data_send(uint8_t ucBytes[HID_KEYBOARD_IN_PACKET_SIZE]);
void hid_mouse_data_send(uint8_t ucButtons, int8_t cX, int8_t cY, int8_t cWhell);

int32_t cdc_acm_datas_receive(void *pvBuff, int32_t iLength);
int32_t cdc_acm_datas_send (void *pvBuff, int32_t iLength);


#endif /* HID_PRINTER_WRAPPER_H */
